package com.hello.booksale.controller;

import com.hello.booksale.entity.BookEntity;
import com.hello.booksale.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;



    @ResponseBody
    @DeleteMapping("/delete/{id}")
    public String bookDelete(@PathVariable("id") int bookId){
        return "";
    }

    @GetMapping("/edit/{id}")
    public String bookEdit(@PathVariable("id") int bookId, Map<String,Object> map){
        map.put("id",bookId);
        return "edit";
    }

    @GetMapping("/detail/{bookId}")
    public String detail(@PathVariable("bookId") int bookId ,HttpServletRequest request){
        BookEntity bookEntity=bookService.selectBookById(bookId);
        request.setAttribute("bookEntity",bookEntity);
        return "/user/detail";
    }

}
